<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function Login(){
    	$this->display();
    }
    public function Loginin(){
    	//var_dump($_POST);
    	//创建模型
    	$login=M('mvp_admin');
    	$login->create();
    	 //查找数据库
        $aname = I('post.adminname');
        $apwd = I('post.adminpwd');
       	$where['ausername'] = array('eq',$aname);
       	$where['apassword'] = array('eq',$apwd);
        $info = $login->where($where)->find();
       // echo $login->_sql();die;
        //var_dump($info);
        if($info['aroles'] != 0){
        	 $this->error('对不起 你没有权限进入后台', U('Admin/Login/Login'),3);
        }
        if(!empty($info)){

            $_SESSION['uid'] = $info['id'];
            $_SESSION['ausername'] = $info['ausername'];
            $_SESSION['aroles'] = $info['aroles'];
            $this->success('恭喜您登陆成功', U('Admin/Index/index'),3);
        }else{
            $this->error('用户名或密码错误', U('Admin/Login/Login'),3);
        }
    }
    public function OutLogin(){
        setcookie('PHPSESSID','',time()-1,'/');
        unset($_SESSION['uid']);
       $arr = session_destroy();
       // var_dump($arr);
         if($arr){
            $this->success('退出成功', U('Admin/Login/login'),3);
        }else{
            $this->error('退出失败', U('Admin/Index/index'),3);
        }
    }
}